#include<bits/stdc++.h>
#define int long long
#define for(i, a, b) for(int (i)=(a); (i)<=(b); (i)++)
using namespace std;
const int N = 1e5;
int T, d[N], v[N], a[N], p[N];
signed main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin >> T;
    while(T--)
    {
        int ans1=0, ans2=0;
        int n, m, L, V;
        cin >> n >> m >> L >> V;
        ans2 = m-1;
        for(i, 1, n)
        {
            cin >> d[i] >> v[i] >> a[i];
            if(v[i] > V) ans1++;
        }
        for(i, 1, m) cin >> p[i];
        cout << ans1 << ' ' << ans2;
    }

    return 0;
}
